//groupnpc.txt - Like basicnpc.txt. Basically, it fidgets around and attacks anything 
//it sees it hates. Also, if it becomes hostile, it sends an alert message to everyone 
//in its group, if it is in a group.
// Memory Cells:
//   Cell 0 - If 0, default behavior. If 1, it doesn't fidget.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 3 - Number of shade to call
// Cell 4 - flee nav pt
begincreaturescript;

variables;

short i,target;
short sent_alert = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Possessed Warrior");
	change_max_health(ME,40);
	set_attitude(ME,10);
	
	if (get_memory_cell(0) == 2)
		set_walk_speed(ME,0);
		
	if (gf(47,11) > 0)
		erase_char(ME);
	break;

beginstate DEAD_STATE;
	if ((what_group_in(ME) >= 0) && (sent_alert == 0) && (get_attitude(ME) >= 10)) {
		alert_char(30000 + what_group_in(ME));
		sent_alert = 1;
		}


		inc_flag(47,14,1);
break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 24)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	// Look for a target, attack it if visible
	if (get_foe_target(ME,8,0)) {
		if (dist_to_party() > 8)
			approach_char(ME,30000,7);
			else {
				do_attack();
				set_state(3);
				}
		}
		
	// Have I been hit? Strike back!
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	
	if (get_attitude(ME) < 10) {
			if (approach_nav_point(ME,get_memory_cell(4),2)) {
					erase_char(ME);
					end();

				}
		}
		else {
	// Otherwise, just peacefully move around. Go back to start, if I'm too far
	// from where I started.
	if ((my_dist_from_start() >= 6) || ((my_dist_from_start() > 0) && (get_memory_cell(0) > 0))) {
		if (get_ran(1,1,100) < 40) 
			return_to_start(ME,1);
		}
		else if (get_memory_cell(0) == 0) {
			fidget(ME,25);
			}
			}
			
	// if we're in combat and the above didn't give me anything to do, just
	// stop now. Otherwise, game will keep running script, and that eats up CPU time.
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	set_amount_adjust(ME,0,5);
	set_amount_adjust(ME,1,5);
	
	if ((what_group_in(ME) >= 0) && (sent_alert == 0) && (get_attitude(ME) >= 10)) {
		alert_char(30000 + what_group_in(ME));
		sent_alert = 1;
		}

	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;

beginstate EVERY_TURN_STATE;
	//if ((tick_difference(last_abil,get_current_tick()) > 1) && (is_combat()) && (target_ok())) {
	//last_abil = get_current_tick();
	//	run_char_animation(3,1,35);	
	//	pc_heard_sound_delay(700,100);	
	//	end();
	//	}

	//	run_char_animation(3,1,35);	
	//	pc_heard_sound_delay(700,100);	

	//	summon_creature(which_char);
	//	set_summon_level(which_char,1);	
	//	place_particle_num(ME,1077,9,8);
	//	run_text_on_char(which_char,"Bamf!",0);

	//run_text_on_char(short which_char_or_group,char *text,short color)
	//add_ability(, 15, which_ability, 0);

	if ((get_attitude(ME) >= 10) && (get_health(ME) < (get_max_health(ME) * 3) / 10)) {
		run_text_on_char(ME,"Shade knocked free!",0);
		set_attitude(ME,3);
		heal_char(ME,get_max_health(ME) / 3);
		set_act_at_dist(ME,1);
		force_char_status(ME,9,1 + difficulty());
		summon_creature(get_memory_cell(3));
		place_particle_num(get_memory_cell(3),1077,9,8);
		
		set_name(get_memory_cell(3),"Mindtaker Spirit");
		run_text_on_char(get_memory_cell(3),"Exorcised!",0);
		if (difficulty() > 0)
			add_ability(get_memory_cell(3), 10, 51, 0);
		
		
		pc_heard_sound_delay(700,100);	
		if (gf(47,16) == 0) {
			sf(47,16,1);
			begin_talk_mode(14);
			}
		end();
		}
break;

beginstate TALKING_STATE;

		print_str("Talking: This warrior is still dizzy. You get no response.");

break;